package com.xr.blog.tools;

import ch.qos.logback.core.PropertyDefinerBase;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 自定义logback获取机器ip变量
 * @author 幸仁杰
 */
public class IpPropertyDefinerBase extends PropertyDefinerBase {

    /**
     * 获取ip地址
     */
    @Override
    public String getPropertyValue() {
        try {
            return InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            return "0.0.0.0";
        }
    }
}
